####################################################################################
#
#  Makefile for Demo Container
#
#  Demo Container - It cans stored data when it's type is std::string.
#  Copyright (C) 2014  Dawei
#  All rights reserved.
#
#  The project is been used for exercise in the MulticoreWare Inc.
#
#  All rights reserved.
#
#####################################################################################

# Define some variables that represents all header files and source files
# It is easy when you want to modify the name of file. 

SRC_DIR=./src
HEADER_DIR=./include/DemoContainer

HEADER_DEMOCONTAINER_COMMON = DemoContainer.h
HEADER_DEMOCONTAINER = DemoContainer.h
HEADER_DEMOCONTAINER_UNITTEST_ALL = DemoContainerUnitTestAll.h
HEADER_DEMOCONTAINER_UNITTEST_ADDITERM = DemoContainerUnitTestAddItem.h
HEADER_DEMOCONTAINER_UNITTEST_GETITEM = DemoContainerUnitTestGetItem.h
HEADER_DEMOCONTAINER_UNITTEST_GETSIZE = DemoContainerUnitTestGetSize.h
HEADER_DEMOCONTAINER_UNITTEST_REMVOEITEM = DemoContainerUnitTestRemoveItem.h

SRC_DEMOCONTAINER = DemoContainer.cpp
SRC_DEMOCONTAINER_UNITTEST = DemoContainerUnitTest.cpp
SRC_DEMOCONTAINER_UNITTEST_ADDITERM = DemoContainerUnitTestAddItem.cpp
SRC_DEMOCONTAINER_UNITTEST_ALL = DemoContainerUnitTestAll.cpp
SRC_DEMOCONTAINER_UNITTEST_GETITEM = DemoContainerUnitTestGetItem.cpp
SRC_DEMOCONTAINER_UNITTEST_GETSIZE = DemoContainerUnitTestGetSize.cpp
SRC_DEMOCONTAINER_UNITTEST_REMVOEITEM = DemoContainerUnitTestRemoveItem.cpp

# Define the variables that represents the name of target and obj for test_hash
TARGET_TEST_DEMOCONTAINER = test_democontainer
OBJ_TEST_DEMOCONTAINER = $(SRC_DEMOCONTAINER:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST_ADDITERM:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST_ALL:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST_GETITEM:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST_GETSIZE:.cpp=.o) $(SRC_DEMOCONTAINER_UNITTEST_REMVOEITEM:.cpp=.o)

# Define some key variables for compiler
CC = g++
CFLAGS = -Wall -Wextra
LDFLAGS = -L./lib -lgtest -lpthread
INCLUDE = -I./include/DemoContainer/ -I./include/ -I./src/

# Default for work that will compile test_democontainer
.PHONY: all
all: $(TARGET_TEST_DEMOCONTAINER)

$(TARGET_TEST_DEMOCONTAINER): $(OBJ_TEST_DEMOCONTAINER)
	$(CC) $(INCLUDE) -o $@ $^ $(LDFLAGS)
	
$(SRC_DEMOCONTAINER:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)
        
$(SRC_DEMOCONTAINER_UNITTEST:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)

$(SRC_DEMOCONTAINER_UNITTEST_ADDITERM:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST_ADDITERM) $(SRC_DIR)/$(HEADER_DEMOCONTAINER_UNITTEST_ADDITERM) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)

$(SRC_DEMOCONTAINER_UNITTEST_ALL:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST_ALL) $(SRC_DIR)/$(HEADER_DEMOCONTAINER_UNITTEST_ALL) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)
	
$(SRC_DEMOCONTAINER_UNITTEST_GETITEM:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST_GETITEM) $(SRC_DIR)/$(HEADER_DEMOCONTAINER_UNITTEST_GETITEM) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)
	
$(SRC_DEMOCONTAINER_UNITTEST_GETSIZE:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST_GETSIZE) $(SRC_DIR)/$(HEADER_DEMOCONTAINER_UNITTEST_GETSIZE) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)
	
$(SRC_DEMOCONTAINER_UNITTEST_REMVOEITEM:.cpp=.o): $(SRC_DIR)/$(SRC_DEMOCONTAINER_UNITTEST_REMVOEITEM) $(SRC_DIR)/$(HEADER_DEMOCONTAINER_UNITTEST_REMVOEITEM) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER) $(HEADER_DIR)/$(HEADER_DEMOCONTAINER_COMMON)
	$(CC) $(INCLUDE) -c $< $(CFLAGS)

# Work for test
.PHONY: test
test: all
	@echo "======================="	
	@echo "Start work for test..."

	-./$(TARGET_TEST_DEMOCONTAINER)

# Work for help
.PHONY: help
help:
	@echo "======================="
	@echo "make all(default)  Making target, test_democontainer."
	@echo "make test  Running the test of test_democontainer."
	@echo "make clean cleaning the file of *.o, *~ and target."
	@echo "======================="

# Work for clean
.PHONY: clean
clean:
	@echo "======================="	
	@echo "Start work for clean..."

	-rm -f *.o
	-rm -f *~
	-rm -f *.xml
	-rm -f ./src/*~
	-rm -f $(TARGET_TEST_DEMOCONTAINER)
	-rm -f $(TARGET_TEST_DEMOCONTAINER).exe
